import Taro from '@tarojs/taro'
import request from './request'

// 封装全局弹窗
Taro.$showMsg = (title = '加载失败...', icon = 'none', duration = 2000) => {
  Taro.showToast({
    title,
    icon,
    duration
  })
}

// 配置请求相关参数
request.baseUrl = 'https://www.wowermaster.com:8855'

request.beforeRequest = (options) => {
  Taro.showLoading({
    title: '加载中...'
  })
  if (options.url.indexOf('/login') === -1) {
    options.header.token = Taro.getStorageSync('token') || ''
  }
}

request.afterRequest = () => {
  Taro.hideLoading()
}

Taro.$http = request
